package com.hyacinth.cloudnote.modules.note.repository;

import com.hyacinth.cloudnote.modules.note.model.Favorite;
import com.hyacinth.cloudnote.modules.note.model.Note;
import com.hyacinth.cloudnote.modules.note.model.NoteBook;
import com.hyacinth.cloudnote.modules.note.model.Tag;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.Repository;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

/**
 * Favorite实体类对应的基础业务Repository
 */
@org.springframework.stereotype.Repository
public interface FavoriteRepository extends Repository<Favorite, UUID> {

    Favorite save(Favorite model);

    Optional<Favorite> findById(UUID id);

    Page<Favorite> findAll(Pageable pageable);

    void delete(Favorite favorite);

    Optional<Favorite> findByNoteAndCreatedBy(Note note, UUID createdBy);

    Optional<Favorite> findByNoteBookAndCreatedBy(NoteBook noteBook, UUID createdBy);

    Optional<Favorite> findByTagAndCreatedBy(Tag tag, UUID createdBy);

    void deleteAllByNote(Note note);

    void deleteAllByNoteIn(List<Note> notes);

    void deleteAllByNoteBook(NoteBook noteBook);

    void deleteAllByTag(Tag tag);
}
